<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div {
            width: 200px;
            height: 200px;
            background-color: lavender;
            position: absolute;
        }
    </style>
</head>

<body>
    <button>移动到400px</button>
    <div>
    </div>
</body>
<script>
    document.querySelector('button').onclick = function () {

        let div = document.querySelector('div');
        let left = div.offsetLeft;
        let times = setInterval(function () {
            left += 10;
            div.style.left = left + 'px';
            if (div.offsetLeft > 400) {
                div.style.left = '400px';
                clearInterval(times);
            }
        }, 50)
    }
</script>

</html>